<?php
/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Badge
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */

class Badge_Plugin_Menus {
	
	public function canViewBadges() {
		$viewer = Engine_Api::_ ()->user ()->getViewer ();
		
		// Must be able to view badges
		if (! Engine_Api::_ ()->authorization ()->isAllowed ( 'badge', $viewer, 'view' )) {
			return false;
		}
		
		return true;
	}
	
	public function canViewRequests() {
		$viewer = Engine_Api::_ ()->user ()->getViewer ();
		
		// Must be able to view badges
		if (! Engine_Api::_ ()->authorization ()->isAllowed ( 'badge', $viewer, 'request' )) {
			return false;
		}
		
		return true;
	}
	
	public function onMenuInitialize_BadgeRequestCreate($row) {
		$viewer = Engine_Api::_ ()->user ()->getViewer ();
		
		if (! $viewer->getIdentity ()) {
			return false;
		}
		
		$badge = Engine_Api::_ ()->core ()->getSubject ( 'badge' );
		
		if (! ($badge instanceof Badge_Model_Badge)) {
			return false;
		}
		
		if (! $badge->award_member_request) {
			return false;
		}
		
		if ($badge->award_member_request == 2 || $badge->testMemberRequirements ( $viewer )) {
			// Modify params
			$params = $row->params;
			$params ['params'] ['badge_id'] = $badge->getIdentity ();
			return $params;
		}
	
	}

}